<template>
	<view class="forget">
		<view class="title">
			<view class="title-tips">重置密码</view>
			<view class="goto" @click="returns">返回</view>
		</view>
		<view class="input">
			<input placeholder="请输入手机号" v-model="from.username"/>
		</view>
		<view class="input input-code">
			<input placeholder="请输入验证码"  v-model="from.verification_code"/>
			<text class="txt" @click="getcode" v-if="!time_num">获取验证码</text>
			<text class="txt code" v-else>{{time_num}}s</text>
		</view>
		<view class="input">
			<input placeholder="设置密码" v-model="from.password"/>
		</view>
		<view class="input">
			<input placeholder="再次输入密码" v-model="new_password"/>
		</view>
		<view class="possword-tips">密码内包含数字字符</view>
		<u-button class="primary" @click="btn" ripple-bg-color="rgba(0,0,0,.4)" :ripple="true">修改</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//获取验证码的倒计时
				time_num:0.,
				// 需要用到的信息
				from:{
					password: '',
					username:'',
					verification_code:'',
				},
				new_password:''
			}
		},
		onLoad() {

		},
		methods:{
			getcode(){
				if(!this.from.username){
					this.$util.taost({
						title:'请输入手机号'
					})
					return false
				}
				this.$http.asyncSendrequest({
					url:'/login/sms_verification_code',
					data:{
						sms_type:'2',
						mobile:this.from.username,
						type:'其他'
					},
					success:res=>{
						if(res.code == 1){
							this.time_num = 60;
							const countdown = setInterval(()=>{
								this.time_num -= 1;
								if(!this.time_num) clearTimeout(countdown);
							},1000)
						} 
						this.$util.taost({
							title:res.msg
						})
					}
				})
			},
			btn() {
				if(!this.from.username){
					this.$util.taost({
						title:'请填写手机号'
					})
					return false
				}
				if(!this.from.verification_code){
					this.$util.taost({
						title:'请填写验证码'
					})
					return false
				}
				if(!this.from.password){
					this.$util.taost({
						title:'请填写密码'
					})
					return false
				}
				if(!this.new_password){
					this.$util.taost({
						title:'请再次输入密码'
					})
					return false
				}
			
				this.$http.asyncSendrequest({
					url:'/profile/updatePassword',
					data:{
						type:1,
						...this.from
					},
					success:res=>{
						
						this.$util.taost({
							title:res.msg,
							callback:v=>{
								if(res.code == '0') {
									this.$util.redirectTo('/pages/login/login');
								}
							}
						})
					}
				})
				
			},
			returns(){
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.forget {
		width: 100%;
		min-height: 100vh;
		padding-top: 178rpx;

		.title {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 0 38rpx 60rpx;
			color: var(--title-project);

			.title-tips {
				font-size: 50rpx;
				font-family: PingFang SC;
				font-weight: bold;
			}

			.goto {
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: bold;
			}
		}

		.input {
			margin: 0 40rpx 24rpx;
			padding: 0 35rpx;
			box-sizing: border-box;
			height: 100rpx;
			border: 1rpx solid #292929;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			position: relative;

			input{
				width: calc(100% - 200rpx);
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
			}
		}

		.input-code {
			justify-content: space-between;
			.txt {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #000000;
			}

			.code {
				color: rgba(0, 0, 0, .4);
			}
		}
		.possword-tips{
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			margin: 0 38rpx;
		}
		.primary{
			height: 100rpx;
			background: #292929;
			border-radius: 100rpx;
			margin: 64rpx 40rpx 0;
			color: #fff;
		}
	}
</style>